package Controls
{
	import Load.DataFormat;
	import Load.LoadData;
	import Load.MixedLoad;
	
	import Objects.GameSprite;
	
	import flash.display.DisplayObject;
	import flash.system.LoaderContext;

	public class SwfLoader extends GameSprite
	{
		private var lastUrl:String="";
		public function SwfLoader()
		{
			super();
		}
		public function load(url:String,context:LoaderContext=null):void
		{
			if(lastUrl==url)return;
			
			lastUrl=url;
			
			var loadData:LoadData=new LoadData();
			loadData.url=url;
			loadData.context=context;
			loadData.dataFormat=DataFormat.IMAGE;
			MixedLoad.load([loadData],finish);
		}
		public function finish(loadData:LoadData):void
		{
			while(sprite.numChildren>0)
			{
				sprite.removeChildAt(0);
			}
			var content:DisplayObject=loadData.data as DisplayObject;
			sprite.addChild(content);
		}
	}
}